package cn.bugstack.infrastructure.dcc;

import cn.bugstack.types.annotations.DCCValue;
import cn.bugstack.types.common.Constants;
import com.sun.org.apache.bcel.internal.generic.LASTORE;
import io.reactivex.rxjava3.core.CompletableOnSubscribe;
import lombok.Data;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class DCCService {


    @DCCValue("downgradeSwitch:0")
    private String downgradeSwitch;

    @DCCValue("cutRange:100")
    private String cutRange;

    @DCCValue("scBlackList:sc0202,sc0203")
    private String scBlackList;

    public boolean isDowngradeSwitch() {
        return "1".equals(downgradeSwitch);
    }

    public boolean isCutRange(String userId){
        int hashCode = Math.abs(userId.hashCode());
        int last = hashCode % 100;
        return last <= Integer.parseInt(cutRange);
    }

    public boolean isScBlackIntercept(String source,String channel){
        List<String> list = Arrays.asList(scBlackList.split(Constants.SPLIT));
        return list.contains(source + channel);
    }

}
